package w83a.w83aOperacionesPaso.w83aLotesPreavisos;

import java.io.InputStream;
import java.sql.Blob;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

public class W83aDescargarDocumentoOutOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//Guardamos la accion en el contexto
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			
			ServletOutputStream out = response.getOutputStream();
			Blob documento=(Blob)contexto.get("ficheroIda");    
	        
	        InputStream inStream = documento.getBinaryStream();
	        
	        response.setContentType("application/octet-stream");
	        response.setHeader("Content-Disposition","attachment;filename=nombreeeeee");
			
	        byte[] outputByte = new byte[4096];
	        while(inStream.read(outputByte, 0, 4096) != -1){
	        	out.write(outputByte, 0, 4096);
	        }
	        inStream.close();
	        out.flush();
	        out.close();
	
			return null;
	}
}
